package com.yx.sql.controller;

import cn.hutool.json.JSONUtil;
import com.yx.common.core.domain.R;
import com.yx.common.websocket.server.WebSocketServer;
import com.yx.common.websocket.vo.MsgResponseVo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * TODO 类作用描述
 *
 * @author sbl
 * @date 2024/11/5
 */
@Slf4j
@Schema(name = "websocket接口")
@RestController
@RequestMapping("/websocket")
public class WebSocketController {
    @Schema(name="websocket-接口测试")
    @GetMapping("/testWebSocket")
    public R<T> testWebSocket() throws IOException {
        //消息体
        MsgResponseVo technicianMsgResponseVo = new MsgResponseVo();
        technicianMsgResponseVo.setRole("Technician");
        technicianMsgResponseVo.setRoleId(1);
        technicianMsgResponseVo.setMsg("您的订单已取消");
        technicianMsgResponseVo.setMsgStatus("CANCEL_ORDER");
        technicianMsgResponseVo.setOrderNo("test");
        //发送消息
        WebSocketServer.sendInfo(JSONUtil.toJsonStr(technicianMsgResponseVo));
        return R.ok();
    }

}
